--Factory Method
--[[
    工厂方法：（创建型）
    作用：封装对象的创建过程
    使用场景：当对象创建比较复杂时，且对象变化不大的时候可以使用。
--]]

require 'Class'

IEnemy = Class()
Enemy_Lv1 = Class(IEnemy)
Enemy_Lv1.Attack = function(self)
    print(string.format('%s执行攻击动作',self.Name))
end
Enemy_Boss = Class(IEnemy)
Enemy_Boss.Attack = function(self)
    print(string.format('%s执行攻击动作',self.Name))
end

IEnemyFactory = Class()
Enemy_Lv1_Factory = Class(IEnemyFactory)
Enemy_Lv1_Factory.Create = function(self,params)
    enemy = Enemy_Lv1:New(params)
    return enemy
end
Enemy_Boss_Factory = Class(IEnemyFactory)
Enemy_Boss_Factory.Create = function(self,params)
    enemy = Enemy_Boss:New(params)
    return enemy
end

--------main--------
function main()
    enemy_Lv1_Factory = Enemy_Lv1_Factory:New()
    enemy_Lv1 = enemy_Lv1_Factory:Create({Name = '等级为1的小兵'})
    enemy_Boss_Factory = Enemy_Boss_Factory:New()
    enemy_Boss = enemy_Boss_Factory:Create({Name = 'Boss'})

    enemy_Lv1:Attack()  --等级为1的小兵执行攻击动作
    enemy_Boss:Attack()  --Boss执行攻击动作
end

main()
